package networkListener;

/**
 * @author re0hg
 * @version 1.0
 * @date 2025/3/28
 */

import org.pcap4j.core.*;

public class Main {
    public static void main(String[] args) {
        try {
            System.out.println("Listing all network interfaces:");

            // 打印所有网络接口，供选择
            Pcaps.findAllDevs().forEach(dev -> {
                System.out.println("Device Name: " + dev.getName());
                System.out.println("Device Description: " + dev.getDescription());
            });

            // 选择回环接口设备：根据你的截图，应该选择 BSD loopback
            PcapNetworkInterface device = Pcaps.findAllDevs().stream()
                    .filter(dev -> dev.getDescription().contains("loopback") || dev.getDescription().contains("BSD"))
                    .findFirst()
                    .orElseThrow(() -> new RuntimeException("Network interface not found"));

            System.out.println("Using network interface: " + device.getDescription());

            // 初始化并开始监听
            NetworkListener listener = new NetworkListener(device);
            listener.startListening();

        } catch (PcapNativeException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }
}

